package com.qf.workqueue;

import com.qf.util.ConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;

/**
 * work queue模式的生产者
 */
public class Publisher {

    @Test
    public void publish() throws Exception {
        //1. 创建连接对象
        Connection connection = ConnectionUtil.getConnection();

        //2. 构建通道
        Channel channel = connection.openChannel().get();

        //3. 基于通道发送多条消息
        String msg = "work queue模式的消息";
        for (int i = 0; i < 10; i++) {
            channel.basicPublish("","workqueue_queue",null,(msg + i).getBytes());
        }
        System.out.println("发送完毕10条消息！");

        //4. 释放资源
        channel.close();
        connection.close();
    }

}
